package com.zx.callback.common.alipay;

import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.zx.callback.common.properties.AlipayConfig;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 支付宝api
 * Created by yanst on 2017/7/28.
 */
public class AlipayApi {
    private static final Logger LOG = LoggerFactory.getLogger(AlipayApi.class);

    /**
     * 支付宝RSA签名验证
     * @param paramsMap
     * @return
     */
    public static boolean rsaSignCheck(Map<String, String> paramsMap) {
        //调用SDK验证签名
        try {
            return AlipaySignature.rsaCheckV1(paramsMap, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
        } catch (AlipayApiException e) {
            LOG.error("支付宝RSA签名验证出现异常", e);
        }
        return false;
    }

    /**
     * 支付宝app客户端RSA签名验证
     * @param content
     * @param sign
     * @return
     */
    public static boolean rsaSignCheckForApp(String content, String sign) {
        //调用SDK验证签名
        try {
            return AlipaySignature.rsaCheck(content, sign, AlipayConfig.alipay_public_key, AlipayConfig.charset, AlipayConfig.sign_type);
        } catch (AlipayApiException e) {
            LOG.error("支付宝RSA签名验证出现异常", e);
        }
        return false;
    }


}
